package com.lazy.app.ui.act;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.res.ResourcesCompat;

import com.lazy.app.BuildConfig;
import com.lazy.app.R;
import com.lazy.app.databinding.ActivityDebugBinding;
import com.lazy.app.presenter.DebugPresenter;
import com.zndroid.base.ui.common.CommonActivity;
import com.zndroid.utils.XUtils;
import com.zndroid.widget.title.TitleBar;

/**
 * 后门系统，可用于调试或者一些总开关控制
 *
 * @author lzy
 */
public class DebugActivity extends CommonActivity<ActivityDebugBinding, DebugPresenter> {
    @Override
    protected int onSupplyStatusBarColor() {
        return Color.parseColor("#498428");
    }

    @Override
    protected ActivityDebugBinding onSupplyViewBinding(@NonNull LayoutInflater layoutInflater) {
        return ActivityDebugBinding.inflate(layoutInflater);
    }

    @Override
    protected TitleBar onSupplyTitleBar() {
        return currentViewBinding().tbTitle;
    }

    @Override
    protected void onBackClickTitleRight() {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    protected void onBackClickTitleLeft() {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    protected void doPreOnBackPressed() {
        //物理按键返回时，通知重新闪屏
        setResult(RESULT_OK);
    }

    @Override
    protected void onBackNetChanged(boolean isConnect, String type, int signalLevel) {
        super.onBackNetChanged(isConnect, type, signalLevel);
        if (isConnect) {
            currentViewBinding().sivNetStatue.setBackgroundColor(ResourcesCompat.getColor(getResources(), android.R.color.holo_green_dark, getTheme()));
        } else {
            currentViewBinding().sivNetStatue.setBackgroundColor(ResourcesCompat.getColor(getResources(), android.R.color.holo_red_dark, getTheme()));
        }
    }

    @Override
    protected void doOnInitViewAfterAllReady(View rootView) {
        super.doOnInitViewAfterAllReady(rootView);
        currentViewBinding().tvAppName.setText(getResources().getString(R.string.txt_common_place_holder, "应用名称", XUtils.create().appUtil().getApplicationName(this)));
        currentViewBinding().tvAppVersion.setText(getResources().getString(R.string.txt_common_place_holder, "应用版本", XUtils.create().appUtil().getVersionName(this)));
        currentViewBinding().tvAppPackageName.setText(getResources().getString(R.string.txt_common_place_holder, "应用包名", XUtils.create().appUtil().getPackageName(this)));
        currentViewBinding().tvAppHost.setText(getResources().getString(R.string.txt_common_place_holder, "接口地址", BuildConfig.BASE_URL));
    }
}
